//小仓库 关于layout的设置
import { defineStore } from "pinia";
import { reqGetArticleType, reqAddArticleType, reqDeleteArticleType, reqDeleteArticleTypes, reqUpdateArticleType, reqSerachArticleType, reqGetArticleTypeNumber } from "@/api/artcleType";
import { ElMessage } from "element-plus";

let useArtcleTypeStore = defineStore("ArtcleTypeStore", {
  state: () => {
    return {
      artcletype: []
    };
  },
  // 异步 | 逻辑的地方
  actions: {
    async getArtcleType(pageNo: number, limit: number) {
      let result = await reqGetArticleType(pageNo, limit);
      if (result.code == 200) {
        this.artcletype = result.data;
      }
    },
    async addArtcleType(data: any) {
      let result = await reqAddArticleType(data);
      if (result.code == 200) {
        ElMessage.success("添加成功");
      } else {
        ElMessage.error("添加失败");
      }
    },
    async deleteArtcleType(id: number) {
      let result = await reqDeleteArticleType(id);
      if (result.code == 200) {
        ElMessage.success("删除成功");
      } else {
        ElMessage.error("删除失败");
      }
    },
    async deleteArtcleTypes(ids: number[]) {
      let result = await reqDeleteArticleTypes(ids);
      if (result.code == 200) {
        ElMessage.success("删除成功");
      } else {
        ElMessage.error("删除失败");
      }
    },
    async updateArtcleType(data: any) {
      let result = await reqUpdateArticleType(data);
      if (result.code == 200) {
        ElMessage.success("修改成功");
      } else {
        ElMessage.error("修改失败");
      }
    },
    async searchArtcleType(data: any) {
      var data1 = JSON.stringify(data);
      let result = await reqSerachArticleType(data1);
      if (result.code == 200) {
        this.artcletype = result.data;
      } else {
        ElMessage.error("没有该文章类型")
      }
    },
    async getArtcleTypeNumber() {
      let result = await reqGetArticleTypeNumber();
      return result.data;
    }
  },
  getters: {

  }
});

export default useArtcleTypeStore;